package jee.boot.common.service;

import jee.boot.common.basic.CrudService;
import jee.boot.common.dao.SerialNumberDao;
import jee.boot.entity.system.SerialNumber;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SerialNumberService extends CrudService<SerialNumberDao, SerialNumber> {
    @Autowired
    private SerialNumberHandler serialNumberHandler;

    public boolean checkAndUpdateVersionAndStatus(SerialNumber serialNumber) {
        return dao.checkAndUpdateVersionAndStatus(serialNumber);
    }

    /**
     * 产生一个新的序列号
     *
     * @param entity
     * @return
     */
    public SerialNumber newSerial(SerialNumber entity) {
        String serialNumber = serialNumberHandler.getSerialNumber(entity.getType(), entity.getCategory(), entity.getSerialNumberFormat());
        entity.setSerialNumber(serialNumber);
        return entity;
    }
}
